package com.yunhe.authority.controller.wechat;

import com.yunhe.authority.domain.authority.Menu;
import com.yunhe.authority.domain.wechat.KingKongDistrictDTO;
import com.yunhe.authority.service.wechat.KingKongDistrictService;
import com.yunhe.common.annotation.OperationRecord;
import com.yunhe.common.constant.SystemConsts;
import com.yunhe.common.exception.ArgumentErrorException;
import com.yunhe.common.model.ResultObject;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author zhengbo
 * @date 2021/10/19 14:51
 */
@Api(value = "KingKongDistrictController", description = "金刚区", tags = {"金刚区"})
@RestController
@RequestMapping("/kingKongDistrict")
public class KingKongDistrictController {

    @Autowired
    private KingKongDistrictService kingKongDistrictService;

    /**
     * 微信小程序端保存金刚区
     * @param ids 菜单ids
     * @param parkId 虚拟园区Id
     * @param usePlatform 使用平台
     * @exception ArgumentErrorException
     */
    @ApiOperation("保存金刚区")
    @ApiImplicitParams({

    })
    @RequestMapping(value = "/creatKingKongDistrict" ,method = RequestMethod.POST)
    @OperationRecord(menu = "微信小程序金刚区", actionType = SystemConsts.ACTION.ADD)
    public ResponseEntity<ResultObject<String>> creatKingKongDistrict(@RequestParam(value = "ids") String ids,
                                                                      @RequestParam(value = "parkId") Long parkId,
                                                                      @RequestParam(value = "usePlatform") String usePlatform)
            throws ArgumentErrorException {
        kingKongDistrictService.saveKingKongDistrict(ids, parkId, usePlatform);
        return new ResponseEntity<>(new ResultObject<>("success"), HttpStatus.OK);
    }

    /**
     * web端查询金刚区
     * @param parkId 虚拟园区id
     * @param usePlatform 使用平台
     */
    @ApiOperation("web端查询金刚区")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "parkId", value = "虚拟园区id", dataType = "Long", paramType = "query"),
            @ApiImplicitParam(name = "usePlatform", value = "使用平台 1小程序 2app端", dataType = "String", paramType = "query"),
    })
    @RequestMapping(value = "/findByParkIdAndUsePlatform" ,method = RequestMethod.POST)
    public ResponseEntity<ResultObject<KingKongDistrictDTO>> findKingKongDistrict(@RequestParam(value = "parkId") Long parkId,
                                                                         @RequestParam(value = "usePlatform") String usePlatform) {
        KingKongDistrictDTO result = kingKongDistrictService.findKingKongDistrictMenuByParkId(parkId, usePlatform);
        return new ResponseEntity<>(new ResultObject<>(result), HttpStatus.OK);
    }

    /**********************wechat*************************/

    /**
     * 查询微信小程序端金刚区
     * @param parkId 虚拟园区id
     */
    @ApiOperation("查询微信小程序端金刚区")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "parkId", value = "虚拟园区id", dataType = "Long", paramType = "query"),
            @ApiImplicitParam(name = "roleIds", value = "角色id", dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "companyId", value = "企业id", dataType = "Long", paramType = "query")
    })
    @RequestMapping(value = "/findWechatKingKongDistrict" ,method = RequestMethod.POST)
    public ResponseEntity<ResultObject<List<Menu>>> findWechatByParkId(@RequestParam(value = "parkId") Long parkId,
                                                                       @RequestParam(value = "roleIds") String roleIds,
                                                                       @RequestParam(value = "companyId") Long companyId) {
        //usePlatform 使用平台 1小程序 2app端
        List<Menu> result = kingKongDistrictService.findKingKongDistrictMenuByRoleIdAndCompanyIdAndParkId(roleIds,parkId,companyId,"1");
        return new ResponseEntity<>(new ResultObject<>(result), HttpStatus.OK);
    }

    @ApiOperation("查询微信小程序端菜单更多")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "parkId", value = "虚拟园区id", dataType = "Long", paramType = "query"),
            @ApiImplicitParam(name = "roleIds", value = "角色id", dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "companyId", value = "企业id", dataType = "Long", paramType = "query")
    })
    @RequestMapping(value = "/findWeChatMenuMore" ,method = RequestMethod.POST)
    public ResponseEntity<ResultObject<List<Menu>>> findWechatMoreMenuByParkId(@RequestParam(value = "parkId") Long parkId,
                                                                       @RequestParam(value = "roleIds") String roleIds,
                                                                       @RequestParam(value = "companyId") Long companyId) {
        //usePlatform 使用平台 1小程序 2app端
        List<Menu> result = kingKongDistrictService.findDistrictMenuByRoleIdAndCompanyIdAndParkId(roleIds,parkId,companyId,"1");
        return new ResponseEntity<>(new ResultObject<>(result), HttpStatus.OK);
    }

    /**********************app*************************/

    /**
     * 查询app金刚区
     * @param parkId 虚拟园区id
     */
    @ApiOperation("查询app金刚区")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "parkId", value = "虚拟园区id", dataType = "Long", paramType = "query"),
            @ApiImplicitParam(name = "roleIds", value = "角色id", dataType = "String", paramType = "query")
    })
    @RequestMapping(value = "/findAppKingKongDistrict" ,method = RequestMethod.POST)
    public ResponseEntity<ResultObject<List<Menu>>> findAppByParkId(@RequestParam(value = "parkId") Long parkId,
                                                                    @RequestParam(value = "roleIds") String roleIds) {
        //usePlatform 使用平台 1小程序 2app端
        List<Menu> result = kingKongDistrictService.findKingKongDistrictMenuByRoleIdAndParkId(roleIds,parkId,"2");
        return new ResponseEntity<>(new ResultObject<>(result), HttpStatus.OK);
    }

    @ApiOperation("查询app菜单更多")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "parkId", value = "虚拟园区id", dataType = "Long", paramType = "query"),
            @ApiImplicitParam(name = "roleIds", value = "角色id", dataType = "String", paramType = "query")
    })
    @RequestMapping(value = "/findAppMenuMore" ,method = RequestMethod.POST)
    public ResponseEntity<ResultObject<List<Menu>>> findAppMenuMoreByParkId(@RequestParam(value = "parkId") Long parkId,
                                                                    @RequestParam(value = "roleIds") String roleIds) {
        //usePlatform 使用平台 1小程序 2app端
        List<Menu> result = kingKongDistrictService.findAppMenuMoreByParkId(roleIds,parkId,"2");
        return new ResponseEntity<>(new ResultObject<>(result), HttpStatus.OK);
    }
}
